home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / XPK / Source / test / testNILPack.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-02  |  2.8 KB  |  133 lines

  1. #define NAME     "testNILPack"
  2. #define REVISION "0"
  3.  
  4. /* Programmheader
  5.  
  6.     Name:        testNILPack
  7.     Author:        SDI
  8.     Distribution:    PD
  9.     Description:    tests Xpk with NIL argument function
  10.     Compileropts:    -
  11.     Linkeropts:    -l xpkmaster amiga
  12.  
  13.  1.0   01.04.97 : first version
  14. */
  15.  
  16. #include <pragma/dos_lib.h>
  17. #include <pragma/xpkmaster_lib.h>
  18. #include <pragma/exec_lib.h>
  19. #include "SDI_defines.h"
  20.  
  21. #ifdef __MAXON__
  22.   #define __asm
  23.   #define __saveds
  24. #endif
  25.  
  26. struct Library *XpkBase;
  27.  
  28. LONG __asm __saveds chunkfunc(register __a1 struct XpkProgress *prog)
  29. {
  30.   switch(prog->xp_Type)
  31.   {
  32.   case XPKPROG_START: PutStr("Start: "); break;
  33.   case XPKPROG_MID: PutStr("\rMid  : "); break;
  34.   case XPKPROG_END: PutStr("\rEnd  : "); break;
  35.   }
  36.  
  37.   if(prog->xp_Type != XPKPROG_END)
  38.     Printf("%4s: %-8s (%3ld%% done, %2ld%% CF, %6ld cps) %s",
  39.       prog->xp_PackerName, prog->xp_Activity, prog->xp_Done,
  40.       prog->xp_CF, prog->xp_Speed, prog->xp_FileName);
  41.   else
  42.     Printf("%4s: %-8s (%3ldK, %2ld%% CF, %6ld cps) %s\033[K\n",
  43.       prog->xp_PackerName, prog->xp_Activity, prog->xp_ULen >> 10,
  44.       prog->xp_CF, prog->xp_Speed, prog->xp_FileName);
  45.  
  46.   Flush(Output());
  47.   return (LONG) SetSignal(0, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C;
  48. }
  49.  
  50. struct Hook chunkhook = { {0}, (ULONG (*)()) chunkfunc};
  51.  
  52. void main(int argc, char **argv)
  53. {
  54.   STRPTR obuf = 0;
  55.   ULONG fh, err, obuflen = 0, olen = 0;
  56.  
  57.   if(argc != 2)
  58.   {
  59.     VPrintf("Filename needed\n", 0);
  60.     exit(0);
  61.   }
  62.  
  63.   if(!(XpkBase = OpenLibrary("xpkmaster.library", 4)))
  64.     exit(10);
  65.  
  66.   if(!(fh = Open("NIL:", MODE_NEWFILE)))
  67.   {
  68.     VPrintf("Could not open fh\n", 0);
  69.     CloseLibrary(XpkBase);
  70.     exit(10);
  71.   }
  72.  
  73.   VPrintf("Testing FH Pack access\n", 0);
  74.  
  75.   if((err = XpkPackTags(
  76.     XPK_InName,    argv[1],
  77.     XPK_OutFH,    fh,
  78.     XPK_ChunkHook,    &chunkhook,
  79.     XPK_PackMethod,    "NUKE",
  80.     TAG_DONE)))
  81.     XpkPrintFault(err, "FH Pack try");
  82.  
  83.   VPrintf("Testing Name Pack access\n", 0);
  84.  
  85.   if((err = XpkPackTags(
  86.     XPK_InName,    argv[1],
  87.     XPK_OutName,    "NIL:",
  88.     XPK_ChunkHook,    &chunkhook,
  89.     XPK_PackMethod,    "NUKE",
  90.     TAG_DONE)))
  91.     XpkPrintFault(err, "Name Pack try");
  92.  
  93.   VPrintf("Producing packed file\n", 0);
  94.  
  95.   if((err = XpkPackTags(
  96.     XPK_InName,        argv[1],
  97.     XPK_PackMethod,        "NUKE",
  98.     XPK_GetOutBuf,        &obuf,
  99.     XPK_GetOutBufLen,     &obuflen,
  100.     XPK_GetOutLen,         &olen,
  101.     XPK_ChunkHook,        &chunkhook,
  102.     TAG_DONE)))
  103.     XpkPrintFault(err, "Normal Pack try");
  104.  
  105.   VPrintf("Testing FH Unpack access\n", 0);
  106.  
  107.   if((err = XpkUnpackTags(
  108.     XPK_InBuf,    obuf,
  109.     XPK_InLen,    olen,
  110.     XPK_OutFH,    fh,
  111.     XPK_ChunkHook,    &chunkhook,
  112.     TAG_DONE)))
  113.     XpkPrintFault(err, "FH Unpack try");
  114.  
  115.   VPrintf("Testing direct Unpack access\n", 0);
  116.  
  117.   if((err = XpkUnpackTags(
  118.     XPK_InBuf,    obuf,
  119.     XPK_InLen,    olen,
  120.     XPK_OutName,    "NIL:",
  121.     XPK_ChunkHook,    &chunkhook,
  122.     TAG_DONE)))
  123.     XpkPrintFault(err, "Name Unpack try");
  124.  
  125.   if(obuf)
  126.     FreeMem(obuf, obuflen);
  127.  
  128.   if(!Close(fh))
  129.     VPrintf("Could not close fh\n", 0);
  130.   CloseLibrary(XpkBase);
  131. }
  132.  
  133.